<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('任务执行日志')" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">

     <input type="hidden" id="jobId" name="jobId" th:value="${jobId}">
    <div class="btn-group-sm" id="toolbar" role="group">
      <a class="btn btn-danger" onclick="clearAll(this);" data-id="0" data-role="0">
        <i class="fa fa-trash"></i> 清空日志
      </a>
      <a class="btn btn-danger" onclick="cancel(this);" data-id="0" data-role="0">
        <i class="fa fa-reply-all"></i>关闭
      </a>
    </div>
    <div class="col-sm-12 select-table table-striped">
      <table id="dataTable"></table>
    </div>
  </div>
</div>
<div id="logDiv" class="ibox" style="display:none;">

  <div class="ibox-content">
    <div class="well">
      <h4 id="logTime"></h4>
      <div class="original" id="log">

      </div>
    </div>
  </div>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript" th:inline="javascript">
  let $table;
  $(function() {
    loadData();
  });


  function loadData(){
    let options = {
      url: "/monitor/job/jobLogData",
      pageNumber: 1,                      // 初始化加载第一页，默认第一页,并记录
      pageSize: 10,                       // 每页的记录行数（*）
      pageList: "10, 25, 50, 100",        // 可供选择的每页的行数（*）
      queryParams: function (params) {
        let p = {
          pageNumber: params.pageNumber,
          pageSize: params.pageSize,
          jobId:$('#jobId').val()
        }
        return p;
      },
      columns: [
        {
          field: 'excuteTime', title: '执行时间', align: 'center'
        },
        {
          field: 'elapsedTime', title: '执行耗时', align: 'center'
        },
        {
          field: 'excuteResult', title: '执行结果', align: 'center', formatter: function (v) {
            if (v === 1) {
              return '<span class="label label-danger">失败</span>';
            }
            return '<span class="label label-primary">成功</span>';
          }
        },
        {
          field: 'id', title: '操作', align: 'center', formatter: renderOpts
        }
      ]
    };
    $table=$('#dataTable').easyTable(options);
  }


  function renderOpts(v,r,index) {
    if (r.excuteResult == 1) {
      var html = '<a data-role="0" class="btn btn-white btn-bitbucket" title="View" href="javascript:void(0);" onclick="detail(this)" data-id="' + v + '"><i class="fa fa-eye"></i></a>';
      return html;
    }
    return '';
  }


  function detail(obj) {
    $('#log').text('');
    let rowId = $(obj).data('id');
    let row = $table.easyTable('getRowById', rowId);
    if (row) {
      $('#log').text(row.errorMessage);
      layer.open({
        title:'任务异常信息',
        type: 1,
        skin: 'layui-layer-rim', //加上边框
        area: ['800px', '600px'], //宽高
        content: $('#logDiv')
      });
    }


  }

  function clearAll() {
    jutils.confirm('确认清空日志吗',
            function () {
              jutils.ajaxGet('/monitor/job/ClearJobLog', { jobId: $('#jobId').val()},
                      function () {
                         $table.easyTable('search');
                      });
            });
  }

  function query() {
    $table.easyTable('search');
  }

  function cancel() {
    jutils.closeDialog();
  }
</script>
</body>
</html>